<template>
  <div>
    <!-- 面包屑  -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图  -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable>
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 订单列表  -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="序号" width="50px"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格(元)" prop="order_price" width="120px"></el-table-column>
        <el-table-column label="是否付款" width="180px">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === '1'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="90px"></el-table-column>
        <el-table-column label="下单时间" width="180px">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="showProgressBox"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryInfo.pagenum"
                     :page-sizes="[2, 5, 10, 20]"
                     :page-size="queryInfo.pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total" background>
      </el-pagination>
    </el-card>
    <!--  修改订单地址  -->
    <el-dialog
      title="编辑订单"
      :visible.sync="addressDialogVisible"
      width="50%" @close="addressDialogClosed">
      <!--  内容主体区域    -->
      <el-form ref="editAddressRef"
               :model="editAddressForm"
               :rules="editAddressRules"
               label-width="80px">
        <!-- 省市区/县 -->
        <el-form-item label="省市区/县">
          <el-cascader
            v-model="editAddressForm.address1"
            :options="cityData"></el-cascader>
        </el-form-item>
        <!-- 详细地址 -->
        <el-form-item label="详细地址">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressDialogVisible = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </span>
    </el-dialog>
    <!--  物流进度  -->
    <el-dialog
      title="物流进度"
      :visible.sync="progressDialogVisible"
      width="30%">
      <div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import cityData from './citydata'
  export default {
    name: 'Order',
    data () {
      return {
        // 订单查询对象
        queryInfo: {
          query: '',
          pagenum: 1,
          pagesize: 10
        },
        // 总订单数量
        total: 0,
        // 订单列表
        orderList: [],
        // 修改订单地址对话框是否显示
        addressDialogVisible: false,
        // 编辑订单地址表单对象
        editAddressForm: {
          address1: [],
          address2: ''
        },
        // 编辑订单地址表单校验规则
        editAddressRules: {
          address1: [
            {
              required: true,
              message: '请输入省市区县',
              trigger: 'blur'
            }
          ],
          address2: [
            {
              required: true,
              message: '请输入详细地址',
              trigger: 'blur'
            }
          ]
        },
        // 省市县对应数据
        cityData,
        // 物流进度对话框是否展示
        progressDialogVisible: false,
        progressInfo: []
      }
    },
    created () {
      this.getOrderList()
    },
    methods: {
      async getOrderList () {
        const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
        if (res.meta.status !== 200) return this.$message.error('获取订单数据失败！')
        this.orderList = res.data.goods
        this.total = res.data.total
      },
      handleSizeChange(pageSize) {
        this.queryInfo.pagesize = pageSize
        this.getOrderList()
      },
      handleCurrentChange(pageNum) {
        this.queryInfo.pagenum = pageNum
        this.getOrderList()
      },
      // 修改订单地址
      showBox() {
        this.addressDialogVisible = true
      },
      // 编辑地址栏窗口关闭事件
      addressDialogClosed() {
        this.$refs.editAddressRef.resetFields()
      },
      async showProgressBox() {
        const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
        if (res.meta.status !== 200) return this.$message.error('获取物流信息失败！')
        this.progressInfo = res.data
        this.progressDialogVisible = true
      }
    }
  }
</script>

<style scoped lang="less">
  .el-cascader {
    width: 100%;
  }
</style>
